<?php
/**
 * WB_CacheeAccel class
 * 
 * @author Jean-Lou Dupont
 * @version @@package-version@@
 * @id $Id: CacheeAccel.php 96 2008-03-07 01:09:46Z jldupont $
 */

// WB_CacheClass and WB_Singleton_IF must anyhow
// have been required' through WB_CacheManager
 //{{include
 
 //include}}
 
 class WB_CacheeAccel
 	extends WB_CacheClass
	implements WB_Singleton_IF
 {
 	/**
 	 * Constructor
 	 */
	public function __construct( $params = null )
	{
		parent::__construct( $params );
	}
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// WB_BaseClass
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
	/**
	 * @see WB_BaseClass::getClassPath
	 */
	public function getClassPath()
	{
		return 'web-bloks/CachesMemory';
	}
	/**
	 * @see WB_BaseClass::getClassVersion
	 * @return 
	 */
	public function getClassVersion()
	{
		return '$Id: CacheeAccel.php 96 2008-03-07 01:09:46Z jldupont $';
	}
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		
	// WB_Singleton_IF Interface
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%				
	/**
	 * @private
	 */
	static $instance = null;

	/**
	 * @see WB_Singleton_IF
	 */
	public static function getSingleton( $params = null )	
	{ 
		/**
		 * @see WB_BaseClass::_handleSingleton
		 */
		return self::_handleSingleton( self::$instance, 'WB_CacheeAccel', $params );
	}
		
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%		
	// WB_CacheClass Interface
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%			
	public function isFake()
	{
		return false;
	}				
		
	public function getInfo()
	{
		return array();
		// broken
		//return eaccelerator_info();
	}

	public static function checkPresence()
	{
		return function_exists( 'eaccelerator_get' );		
	}
	/**
	 * Only clears the elements marked for deletion
	 * i.e. does not perform an unconditional 'clear' of
	 * all entries.
	 */
	public function clearCache()
	{
		return eaccelerator_clear();
	}

	function get($key) 
	{
		$val = eaccelerator_get( $key );

		if ( $val === null )
			return false;
			
		if ( is_string( $val ) ) 
			$val = unserialize( $val );

		return $val;
	}

	function set($key, $value, $exptime=0) 
	{
		return eaccelerator_put( $key, serialize( $value ), $exptime );
	}

	function delete($key, $time=0) 
	{
		return eaccelerator_rm( $key );
	}

	function lock($key, $waitTimeout = 0 ) 
	{
		return eaccelerator_lock( $key );
	}

	function unlock($key) 
	{
		return eaccelerator_unlock( $key );
	}
}// END eAccel

// registers this shared memory cache
WB_CacheManager::register( 'WB_CacheeAccel' );